<?php
/*
 * @Author: your name
 * @Date: 2020-04-24 13:41:08
 * @LastEditTime: 2020-04-28 16:26:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ztaudio-activity\app\Http\Controllers\BoatController.php
 */

namespace App\Http\Controllers;

use App\Http\Model\Config;
use App\Http\Model\Gift;
use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\User;
use App\Http\Model\UserM;
use App\Http\Model\Boat;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\AudioApi;
use Illuminate\Support\Facades\DB;

/*
 *
 * */

class BoatController extends BaseController
{
    protected $model;
    protected $configModel;
    protected $gift_model;
    protected $user_model;
    private $audioApi;
    // protected $giftBoatServices;
    protected $table = 'gift_boat_ticket_log';

    const CACHE_CHIP_KEY = "REDIS:BOAT:CHIP_KEY:";//碎片
    const CACHE_RAFFLE_TICKET = "REDIS:BOAT:RAFFLE_TICKET:";//抽奖券
    const CACHE_SCORE_CARD = "REDIS:BOAT:SCORE_CARD";//用户积分
    const CACHE_USER_GIFT_KEY = "REDIS:BOAT:GIFT_KEY:";//用户礼物
    // CONST CACHE_SENDER_KEY = "REDIS:BOTA:SENDER:";//赠送礼物
    // CONST CACHE_RECEIVER_KEY = "REDIS:BOTA:RECEIVER:";//接受礼物
    const CACHE_USER_TASK_OF_DAY = "REDIS:BOTA:TASK_DAY:";//每日任务
    const CACHE_USER_FOLLOW_OF_DAY = "REDIS:BOTA:FOLLOW_DAY:";//每日关注
    const CACHE_USER_CHIP_GIFT = "REDIS:BOAT:USER:CHIP_GIFT_KEY:";//用户碎片礼物时间
    const DATE_ARRAY = [
        ['20200609', '20200630']//活动时间
    ];
    const GIFT_ID_ARR = [224, 223, 225, 209, 170];

    public function __construct()
    {
        // $this->configModel = $config;
        $this->gift_model = new Gift();
        $this->user_model = new UserM();
        $this->audioApi = new AudioApi();
        // $this->giftBoatServices = new GiftBoatServices();
        $this->boat_model = new Boat();
    }

    /**
     * 活动阶段
     *
     * @return void 0 进行中; -1 活动未开始; -2 活动已结束
     */
    private function whichStage()
    {
        // $now = date('Ymd', strtotime('2020-05-26'));//1/9/17/25
        $now = date('Ymd', time());
        if ($now < self::DATE_ARRAY[0][0]) {
            return -1;
        }

        if ($now >= self::DATE_ARRAY[0][0] && $now <= self::DATE_ARRAY[0][1]) {
            return 0;
        }
        return -2;
    }

    /**
     * 消息队列
     *
     * @return void
     */
    public function assignAction($body = [])
    {
        // $body_json = '{"room_id":136,"gift_id":281,"user_id":133,"to_user_id_array":["145"],"gift_num":1,"create":1592807999,"type":0,"consumer_type":1}';
        // $body = json_decode($body_json, true);
        // $body = json_decode($body, true);
        // $body_json = '{"room_id":136,"gift_id":281,"user_id":133,"to_user_id_array":["145"],"gift_num":1,"create":1592833093,"type":0,"consumer_type":1}';
        // $body = json_decode($body_json,true);
        $gift_id = $body['gift_id'];
        $user_id = $body['user_id'];    // 送礼物者
        $to_user_id_array = $body['to_user_id_array'];  // 收礼物者
        $gift_num = $body['gift_num'];                  // 礼物数
        $type = 0; //礼物投票
        $stage = $this->whichStage();

        if ($stage === -1) {
            write_log('boatConsumer', 'timeError', "活动未开始");
            return $stage;
        }

        if ($stage === -2) {
            write_log('boatConsumer', 'timeError', "活动已结束");
            return $stage;
        }

        // 礼物id
        $gift_id_arr = self::GIFT_ID_ARR;
        //礼物积分
        $gift_score_arr = [1000, 5200, 52000];
        //gift_id 指定礼物
        if (!in_array($gift_id, $gift_id_arr)) {
            write_log('boatConsumer', 'giftError', "非指定礼物");
            return;
        }

        if ($stage == 0 && $gift_id_arr[0] == $gift_id) {
            
            $this->score_card($gift_id_arr[0], $gift_score_arr[0], $to_user_id_array, $gift_num, $user_id);

        } elseif ($stage == 0 && $gift_id_arr[1] == $gift_id) {

            $this->score_card($gift_id_arr[1], $gift_score_arr[1], $to_user_id_array, $gift_num, $user_id);

        } elseif ($stage == 0 && $gift_id_arr[2] == $gift_id) {

            $this->score_card($gift_id_arr[2], $gift_score_arr[2], $to_user_id_array, $gift_num, $user_id);

        } elseif ($stage == 0 && $gift_id_arr[3] == $gift_id) {

            $this->taskAdd_1($user_id, 'gift1');

        } elseif ($stage == 0 && $gift_id_arr[4] == $gift_id) {

            $this->taskAdd_1($user_id, 'gift2');

        } else {
            return false;
        }

    }

    public function assignAppShare($body = [])
    {
        // $body_json =  '{"platform":1,"data":{"user_id":133,"trends_id":171,"create_time":1592796987,"type":2},"consumer_type":1}';
        // $body = json_decode($body_json, true);

        $platform = $body['platform'];//来源 1：发布动态通知 2：关注好友通知 3 ：分享通知
        $data = $body['data'];    // 送礼物者

        $stage = $this->whichStage();

        if ($stage === -1) {
            write_log('boatConsumer', 'timeError', "活动未开始");
            return $stage;
        }

        if ($stage === -2) {
            write_log('boatConsumer', 'timeError', "活动已结束");
            return $stage;
        }

        if ($stage == 0) {

            $this->taskAdd($platform, $data);

        } else {
            return false;
        }

    }

    /**
     * 积分/礼物数量增长
     *
     * @param [type] $gift_id                // 礼物id
     * @param [type] $gift_score            // 礼物积分
     * @param [type] $to_user_id_array      // 接收礼物者
     * @param [type] $gift_num              // 礼物数
     * @param [type] $user_id               // 送礼物者
     * @return void
     */
    public function score_card($gift_id, $gift_score, $to_user_id_array, $gift_num, $user_id)
    {

        // 送礼物结合
        $user_gift_key = self::CACHE_USER_GIFT_KEY . $gift_id;
        $score_card = self::CACHE_SCORE_CARD;//用户积分

        //赠送人送礼物数量/积分
        $sender_gift_num = count($to_user_id_array) * $gift_num;
        $sender_gift_score = count($to_user_id_array) * $gift_num * $gift_score;

        //赠送者
        Redis::ZINCRBY($user_gift_key, $sender_gift_num, $user_id);
        Redis::ZINCRBY($score_card, $sender_gift_score, $user_id);

        //接收者
        $receiver_gift_num = $gift_num;
        $receiver_gift_score = $gift_num * $gift_score;
        foreach ($to_user_id_array as $receiver_id) {
            if (!($user_id == $receiver_id)) {
                //礼物数量
                Redis::ZINCRBY($user_gift_key, $receiver_gift_num, $receiver_id);
                //礼物积分
                Redis::ZINCRBY($score_card, $receiver_gift_score, $receiver_id);
            }
        }

    }

    /**
     * 获取用户信息
     *
     * @param Request $request
     * @param integer $id
     * @param UserM $userM
     * @return void
     */
    public function userInfo(Request $request, int $id, UserM $userM)
    {
        // 当前用户信息
        $user_info = $userM->getInviteUserInfo($id);
        $chip_gift_key = self::CACHE_USER_CHIP_GIFT . $id;
        $user_chip_gift = Redis::HGETALL($chip_gift_key);
        $data['user_chip_gift'] = $user_chip_gift;
        $data['user_info'] = $user_info;
        OutJson::toJson(200, '成功', $data);
    }

    /**
     * 获取用户礼物
     *
     * @param [type]  user_id             //
     * @param [type]
     * @return void
     */
    public function getUserGift(Request $request)
    {
        $user_id = $request->get('user_id');

        $res = [];
        $gift_id_arr = self::GIFT_ID_ARR;
        $key_arr = ['common', 'uncommon', 'purpose'];

        foreach ($gift_id_arr as $key => $value) {
            if ($key < 3) {
                $k = $key_arr[$key];
                $user_gift_key = self::CACHE_USER_GIFT_KEY . $value;
                $res[$k] = Redis::ZSCORE($user_gift_key, $user_id) ?? '0';
            }
        }
        OutJson::toJson(200, '成功', $res);
    }

    /**
     * 用户礼物兑换
     *
     * @param [type] user_id              //
     * @param [type] stage
     * @return void
     */
    public function giftUpdate(Request $request)
    {
        $user_id = $request->get('user_id');
        $gift_id_arr = self::GIFT_ID_ARR;
        $gift_num = [-99, -66, -33];
        foreach ($gift_id_arr as $key => $value) {
            if ($key < 3) {
                $user_gift_key = self::CACHE_USER_GIFT_KEY . $value;
                $res = Redis::ZINCRBY($user_gift_key, $gift_num[$key], $user_id);
            }
        }
        $api_data['user_id'] = $user_id;
        $api_data['type'] = 0;
        $api_data['common'] = -99;
        $api_data['uncommon'] = -66;
        $api_data['purpose'] = -33;
        $this->boat_model->createSendChipLog($api_data);

        $res1 = $this->audioApi->sendUsedMall($user_id, 160, 5, 30);//主页飘

        OutJson::toJson(200, '成功');
    }

    /**
     * 轮盘抽取碎片
     *
     * @param [type]$num               // 抽取次数
     * @param [type] user_id
     * @return void
     */
    public function getPrize(Request $request)
    {
        $num = $request->get('num', 1);
        $user_id = $request->get('user_id');
        $arr = [
            [1, 2, 3, 5, 7],
            [4, 8],
            [6]
        ];
        for ($i = 0; $i < $num; $i++) {
            $data[$i] = $this->prize();
        }
        $res['chip']['common_value'] = 0;
        $res['chip']['uncommon_value'] = 0;
        $res['chip']['purpose_value'] = 0;

        foreach ($data as $key => $value) {
            $res['id'] = $value['id'];
            if (in_array($value['id'], $arr[0])) {

                $res['chip']['common_prize'] = $value['prize'];
                $res['chip']['common_value'] += $value['value'];
            }
            if (in_array($value['id'], $arr[1])) {

                $res['chip']['uncommon_prize'] = $value['prize'];
                $res['chip']['uncommon_value'] += $value['value'];
            }
            if (in_array($value['id'], $arr[2])) {

                $res['chip']['purpose_prize'] = $value['prize'];
                $res['chip']['purpose_value'] += $value['value'];
            }
        }
        $api_data['user_id'] = $user_id;
        $api_data['type'] = 1;
        $api_data['common'] = $res['chip']['common_value']??'';
        $api_data['uncommon'] = $res['chip']['uncommon_value']??'';
        $api_data['purpose'] = $res['chip']['purpose_value']??'';
        $this->boat_model->createSendChipLog($api_data);

        //碎片增长
        $this->chipAdd($user_id, $res['chip']);
        OutJson::toJson(200, '成功', $res);
    }
    
    /**
     * 轮盘抽取碎片概率
     *
     * @return void
     */
    private function prize()
    {
        $prize_arr = array(
            '0' => array('id' => 1, 'prize' => '普通碎片', 'v' => 16.4, 'value' => '1'),
            '1' => array('id' => 2, 'prize' => '普通碎片', 'v' => 16.4, 'value' => '1'),
            '2' => array('id' => 3, 'prize' => '普通碎片', 'v' => 16.4, 'value' => '1'),
            '3' => array('id' => 4, 'prize' => '稀有碎片', 'v' => 7, 'value' => '1'),
            '4' => array('id' => 5, 'prize' => '普通碎片', 'v' => 16.4, 'value' => '1'),
            '5' => array('id' => 6, 'prize' => '万能碎片', 'v' => 4, 'value' => '1'),
            '6' => array('id' => 7, 'prize' => '普通碎片', 'v' => 16.4, 'value' => '1'),
            '7' => array('id' => 8, 'prize' => '稀有碎片', 'v' => 7, 'value' => '1'),
        );

        $actor = 100;

        foreach ($prize_arr as $v) {
            $arr[$v['id']] = $v['v'];
        }
        foreach ($arr as &$v) {
            $v = $v * $actor;
        }

        asort($arr);

        $sum = array_sum($arr);   //总概率
        $rand = mt_rand(1, $sum);
        $result = '';    //中奖产品id

        foreach ($arr as $k => $x) {
            if ($rand <= $x) {
                $result = $k;
                break;
            } else {
                $rand -= $x;
            }
        }
        $res = $prize_arr[$result - 1];
        return $res;
    }

    /**
     * 用户 钻石兑换抽奖券 
     *
     * @param [type]$user_id               //
     * @param [type] $num            //
     * @param [type] $type           //抽奖券0减少 1增加
     * @return void
     */
    public function diamion(Request $request)
    {
        $user_id = $request->post('user_id');
        $num = $request->post('number');
        $type = $request->post('type');
        $recharge = [
            'user_id' => $user_id,
            'number' => $num,
            'type' => $type,
        ];
        $res = curl_request(env('KK_API_HOST') . '/finance/diamond/decr', $recharge, 'urlencoded', 'GET');
        $res = json_decode($res, true);
        if ($res['code'] === 0) {

            $api_data['user_id'] = $user_id;
            $api_data['type'] = 0; 
            $api_data['ticket'] = 0;
            $api_data['diamion'] = $num;
            $api_data['from'] = '';
            $this->boat_model->createTicketLog($api_data);

            OutJson::toJson(200, '成功');
        }
        $api_data['created_at'] = date_ymd();
        write_log('boatTicket', 'diamionError', $api_data);//钻石兑换抽奖券失败
        
        OutJson::toJson(201, $res['msg'] ?: '');
    }

    /**
     * 用户 抽奖券 减少
     *
     * @param [type]$user_id               //
     * @param [type] $num            //普通碎片
     * @param [type] $type           //抽奖券0减少 1增加
     * @return void
     */
    public function ticketUpdate(Request $request)
    {
        $user_id = $request->post('user_id');
        $num = $request->post('num');
        $type = $request->post('type');
        $ticket_key = self::CACHE_RAFFLE_TICKET . $user_id;
        if ($type == '1') {
            $api_data['from'] = '钻石';
            $res['ticket'] = Redis::INCRBY($ticket_key, $num);
        } else {
            $api_data['from'] = '';
            $res['ticket'] = Redis::INCRBY($ticket_key, -$num);
        }

        $api_data['user_id'] = $user_id;
        $api_data['type'] = $type; 
        $api_data['ticket'] = $num;
        $api_data['diamion'] = 0;
        $this->boat_model->createTicketLog($api_data);

        OutJson::toJson(200, '成功', $res);
    }

    /**
     * 用户碎片 抽奖券
     *
     * @param [type]$user_id               //
     * @param [type] $common            //普通碎片
     * @param [type]$uncommon            // 稀有碎片
     * @param [type] $purpose             //万能碎片
     * @return void
     */
    public function userChip(Request $request)
    {
        $user_id = $request->get('user_id');
        $ticket_key = self::CACHE_RAFFLE_TICKET . $user_id;
        $chip_key = self::CACHE_CHIP_KEY . $user_id;
        $res = Redis::HGETALL($chip_key);
        if (empty($res)) {
            $res['common'] = 0;
            $res['uncommon'] = 0;
            $res['purpose'] = 0;
        }
        $res['ticket'] = Redis::GET($ticket_key) ?? 0;
        OutJson::toJson(200, '成功', $res);
    }

    /**
     * 碎片增长
     *
     * @param [type]$user_id               //
     * @param [type] $common            //普通碎片
     * @param [type]$uncommon            // 稀有碎片
     * @param [type] $purpose             //万能碎片
     * @return void
     */
    private function chipAdd($user_id, $chip)
    {

        $stage = $this->whichStage();

        if ($stage === -1) {
            write_log('boatController', 'timeError', "活动未开始");
            return $stage;
        }

        if ($stage === -2) {
            write_log('boatController', 'timeError', "活动已结束");
            return $stage;
        }
        $chip_key = self::CACHE_CHIP_KEY . $user_id;
        Redis::HINCRBY($chip_key, 'common', $chip['common_value']);
        Redis::HINCRBY($chip_key, 'uncommon', $chip['uncommon_value']);
        Redis::HINCRBY($chip_key, 'purpose', $chip['purpose_value']);
    }

    /**
     * 碎片兑换礼物
     *
     * @param [type]$num               //
     * @param [type]
     * @return void
     */
    public function chipUpdate(Request $request)
    {
        $stage = $request->get('stage');
        $user_id = $request->get('user_id');
        $chip_key = self::CACHE_CHIP_KEY . $user_id;
        $chip_gift_key = self::CACHE_USER_CHIP_GIFT . $user_id;
        if ($stage == 1) {
            $api = $this->audioApi->sendUsedMall($user_id, 164, 1, 15);//头饰
            if($api){
                $chip['common_value'] = -99;
                Redis::HINCRBY($chip_key, 'common', $chip['common_value']);
                // $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => 155, 'goods_type' => 1, 'time_limit' => 30]);//头饰
                $res = Redis::HGET($chip_gift_key, 'headwear');
                Redis::HSET($chip_gift_key, 'headwear', $res + 1);
            }
            
           
        } elseif ($stage == 2) {
            $api = $this->audioApi->sendMedal($user_id, 43, 0); //勋章
            if($api){
                $chip['common_value'] = -66;
                $chip['uncommon_value'] = -33;
                Redis::HINCRBY($chip_key, 'common', $chip['common_value']);
                Redis::HINCRBY($chip_key, 'uncommon', $chip['uncommon_value']);
                // $this->audioApi->sendMedal($user_id, 19, 0); //勋章
                Redis::HSET($chip_gift_key, 'medal', 1);
            }
            
        } elseif ($stage == 3) {
            $api = $this->audioApi->sendUsedMall($user_id, 163, 2, 15); //座驾
            if($api){
                $chip['uncommon_value'] = -33;
                $chip['purpose_value'] = -22;
                Redis::HINCRBY($chip_key, 'uncommon', $chip['uncommon_value']);
                Redis::HINCRBY($chip_key, 'purpose', $chip['purpose_value']);
                // $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => 159, 'goods_type' => 2, 'time_limit' => 15]); //座驾
                $res = Redis::HGET($chip_gift_key, 'car');
                Redis::HSET($chip_gift_key, 'car', $res + 1);
            }
            
            
        }
        
        $api_data['user_id'] = $user_id;
        $api_data['type'] = 0;
        $api_data['common'] = $chip['common_value']??'';
        $api_data['uncommon'] = $chip['uncommon_value']??'';
        $api_data['purpose'] = $chip['purpose_value']??'';
        $this->boat_model->createSendChipLog($api_data);
        if (!$api) {
            write_log('boatController', 'sendMallApiError', $api_data);//奖励添加失败
            OutJson::toJson(201, '失败');
        }
        OutJson::toJson(200, '成功');
    }

    /**
     * 每日任务
     *
     * @param [type]$user_id              //
     * @param [type] $field               //任务名称  publish：发布  follow:关注 share:分享 gift1: 送出礼物1 gift2:送出礼物2
     * @return void
     */
    private function taskAdd_1($user_id, $field)
    {
        $day = date('Ymd');
        $user_id = $user_id;
        $key = self::CACHE_USER_TASK_OF_DAY . $day . ':' . $user_id;
        $follow_key = self::CACHE_USER_FOLLOW_OF_DAY . $day . ':' . $user_id;
        if (!(Redis::HEXISTS($key, $field))) {
            Redis::HMSET($key, $field, '1');
        }

    }

    /**
     * 每日任务
     *
     * @param [type]$user_id              //
     * @param [type] $field               //任务名称  publish：发布  follow:关注 share:分享 gift1: 送出礼物1 gift2:送出礼物2
     * @return void
     */
    private function taskAdd($platform, $data)
    {
        $day = date('Ymd');
        $user_id = $data['user_id'];
        $key = self::CACHE_USER_TASK_OF_DAY . $day . ':' . $user_id;
        $follow_key = self::CACHE_USER_FOLLOW_OF_DAY . $day . ':' . $user_id;
        switch ($platform) {
            case 1;
                $field = 'publish';
                $type = $data['type'];
                if (!(Redis::HEXISTS($key, $field))) {
                    Redis::HMSET($key, $field, '1');
                }
                break;
            case 2:
                $field = 'follow';
                $res_1 = Redis::SISMEMBER($follow_key, $data['follow_user_id']);
                if ($res_1) {
                    break;
                }
                Redis::SADD($follow_key, $data['follow_user_id']);
                $res = Redis::HGET($key, $field);
                if ($res < 5) {
                    Redis::HINCRBY($key, $field, 1);
                }
                break;
            case 3;
                $field = 'share';
                $type = $data['type'];
                if (!($data['type'] == 4) && !($data['keywords'] == '端午活动')) {
                    break;
                }

                if (!(Redis::HEXISTS($key, $field))) {
                    Redis::HMSET($key, $field, '1');
                }
                break;
        }

    }

    /**
     * 每日任务状态
     *
     * @param [type]$user_id              //
     * @param [type] $field               //任务名称  publish：发布  follow:关注 share:分享 gift1: 送出礼物1 gift2:送出礼物2
     * @return void
     */
    public function getUserTask(Request $request)
    {
        $user_id = $request->get('user_id');
        $day = date('Ymd');
        $key = self::CACHE_USER_TASK_OF_DAY . $day . ':' . $user_id;
        $data = Redis::HGETALL($key);
        OutJson::tojson(200, '成功', $data);
    }

    /**
     * 每日任务状态更改
     *
     * @param [type]$user_id              //
     * @param [type] $stage              //任务名称  1:publish：发布  2:follow:关注 3:share:分享 gift1: 送出礼物1 gift2:送出礼物2
     * @return void
     */
    public function taskUpdate(Request $request)
    {
        $user_id = $request->get('user_id');
        $stage = $request->get('stage');
        $field = ['publish', 'follow', 'share', 'gift1', 'gift2'];
        $day = date('Ymd');
        $key = self::CACHE_USER_TASK_OF_DAY . $day . ':' . $user_id;
        switch ($stage) {
            case '2':
                $data = Redis::HSET($key, $field[$stage - 1], '6');
                break;

            default:
                $data = Redis::HSET($key, $field[$stage - 1], '2');
                break;
        }

        $ticket_key = self::CACHE_RAFFLE_TICKET . $user_id;
        Redis::INCR($ticket_key);
        
        $api_data['user_id'] = $user_id;
        $api_data['type'] = 1; 
        $api_data['ticket'] = 1;
        $api_data['diamion'] = 0;
        $api_data['from'] = '任务'.$stage;
        $this->boat_model->createTicketLog($api_data);

        OutJson::tojson(200, '成功', $data);
    }

    /**
     * l礼物榜单
     *
     * @param [type]$num               //
     * @param [type]
     * @return void
     */
    public function giftList(Request $request)
    {
        $user_id = $request->get('user_id');
        $score_key = self::CACHE_SCORE_CARD;
        $scoreList = Redis::zrevrangebyscore($score_key, '+inf', '-inf', array('withscores' => true, 'limit' => array(0, 30)));
        $userScore = Redis::ZREVRANK($score_key, $user_id);

        $userIdArray = array_keys($scoreList);
        $userIdArray = array_values(array_unique(array_merge([$user_id], $userIdArray)));

        $userKeyList = [];
        if (!empty($userIdArray)) {
            $list = $this->user_model->getFiveWinners($userIdArray)->toArray();
            $userKeyList = array_column($list, null, 'user_id');
        }

        $list = [];
        $currUserRank = $userKeyList[$user_id] ?? [];
        $currUserRank['score'] = '未上榜';
        foreach ($scoreList as $key => $value) {
            $item = $userKeyList[$key] ?? [];
            $item['score'] = $value;
            $list[] = $item;

            if ($key == $user_id and !is_null($userScore)) {
                $currUserRank['score_value'] = $value;
                $currUserRank['score'] = '排名' . ($userScore + 1) . '位';
            }
        }

        $data['data'] = $list;
        $data['data1'] = $currUserRank;

        OutJson::toJson(200, '成功', $data);
    }

    /**
     * l礼物榜单
     *
     * @param [type]$num               //
     * @param [type]
     * @return void
     */
    public function getGiftList(Request $request)
    {
        $user_id = $request->get('user_id');
        // $user_id = 133;
        dd($user_id);
        $user_id_arr = array($user_id);
        $score_key = self::CACHE_SCORE_CARD;
        $num = Redis::ZREVRANK($score_key, $user_id) + 1;

        if (!empty($user_id)) {

            $list1 = $this->user_model->getFiveWinners($user_id_arr)->toArray();
            foreach ($list1 as &$user) {
                $user['score'] = '排名' . $num . '位';
            }

        }
        $data = $list[0] ?? '';
        OutJson::toJson(200, '成功', $data);
    }

    public function test()
    {

    }
}
